package edu.njust.cma.service.impl;

import edu.njust.cma.config.TimeConfig;
import edu.njust.cma.mapper.StandardMapper;
import edu.njust.cma.mapper.StandardMethodMapper;
import edu.njust.cma.pojo.Standard;
import edu.njust.cma.service.StandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StandardServiceImpl implements StandardService {
    @Autowired
    StandardMapper standardMapper;

    @Autowired
    StandardMethodMapper standardMethodMapper;

    //1. 添加新的标准（添入标准库）
    @Override
    public int addStandard(Standard standard) {
        standard.setCreationTime(TimeConfig.getNowTime());
        standardMapper.addStandard(standard);
        int standardId =standard.getId();
        return standardId;
    }

    @Override
    public void addStandardMethod(int standardId, String methodName) {
        standardMethodMapper.addStandardMethod(standardId, methodName);
    }

    @Override
    public List<Standard> getAllStandard() {
        return standardMapper.getAllStandard();
    }

    @Override
    public List<String> getAllMajorCategoryName() {
        return standardMapper.getAllMajorCategoryName();
    }

    @Override
    public List<String> getAllMinorCategoryName(String majorCategoryName) {
        return standardMapper.getAllMinorCategoryName(majorCategoryName);
    }

    @Override
    public List<String> getNumber(String majorCategoryName, String minorCategoryName) {
        return standardMapper.getNumber(majorCategoryName, minorCategoryName);
    }

    @Override
    public Integer getStandardId(String number) {
        return standardMapper.getStandardId(number);
    }

    @Override
    public List<String> getStandardMethod(int standardId) {
        return standardMethodMapper.getStandardMethod(standardId);
    }

    @Override
    public boolean deleteStandard(int standardId) {
        int result = standardMapper.isInProject(standardId);
        if(result == 0) {
            standardMapper.deleteStandardById(standardId);
            return true;
        } else {
            return false;
        }
    }

    //通过Excel导入标准


}
